﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace G.APITest.Controls
{
    [TemplateVisualState(Name = "Edite")]
    [TemplateVisualState(Name = "Normal")]
    public class EditeControl : ContentControl
    {

        public static readonly DependencyProperty IsEditeProperty = DependencyProperty.Register("IsEdite", typeof(bool), typeof(EditeControl), new PropertyMetadata(false, IsEditeChanged));

        private static void IsEditeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            EditeControl edite = d as EditeControl;
            if (edite.IsEdite)
                VisualStateManager.GoToState(edite, "Edite", false);
            else
                VisualStateManager.GoToState(edite, "Normal", false);

        }
        public bool IsEdite
        {
            get
            {
                return (bool)this.GetValue(IsEditeProperty);
            }
            set
            {
                this.SetValue(IsEditeProperty, value);
            }
        }

        public static readonly DependencyProperty EditeContentProperty = DependencyProperty.Register("EditeContent", typeof(object), typeof(EditeControl), null);

        public object EditeContent
        {
            get
            {
                return this.GetValue(EditeContentProperty);
            }
            set
            {
                this.SetValue(EditeContentProperty, value);
            }
        }

        public static readonly DependencyProperty EditeTemplateProperty = DependencyProperty.Register("EditeTemplate", typeof(DataTemplate), typeof(EditeControl), null);

        public DataTemplate EditeTemplate
        {
            get
            {
                return (DataTemplate)this.GetValue(EditeTemplateProperty);
            }
            set
            {
                this.SetValue(EditeTemplateProperty, value);
            }
        }

        public EditeControl()
        {
            this.DefaultStyleKey = typeof(EditeControl);
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            if (this.IsEdite)
                VisualStateManager.GoToState(this, "Edite", false);
            else
                VisualStateManager.GoToState(this, "Normal", false);
        }
    }
}
